package com.anolesoft.yr.mbus.pre.mapper;

import com.anolesoft.yr.mbus.pre.dto.CrmBaseSaveDTO;
import com.anolesoft.yr.mbus.pre.dto.CrmBaseUpdateDTO;
import com.anolesoft.yr.mbus.pre.dto.PreInquirySaveDTO;
import com.anolesoft.yr.mbus.pre.sql.PreInquirySQL;
import com.anolesoft.yr.mbus.pre.vo.ObjectQueryVO;
import com.anolesoft.yr.mbus.pre.vo.PreInquiryQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PreInquiryMapper {

    //新增询盘记录
    @Insert(PreInquirySQL.SAVE_PRE_INQUIRY)
    int savePreInquiry(PreInquirySaveDTO preInquirySaveDTO);

    //推广记录是否生成询盘记录
    @Select(PreInquirySQL.QUERY_PRE_INQUIRY_BY_PROMOTE_UID)
    @Results(id = "queryPreInquiryByPromoteUid", value = {
            @Result(column = "count", property = "count")
    })
    int queryPreInquiryByPromoteUid(String prePromoteUid);

    //查询配件信息（临时查询，正常应该在配件接口中）
    @Select(PreInquirySQL.QUERY_PART_MODEL_PART_NAME)
    @Results(id = "queryPartModelName", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "part_name", property = "partName")
    })
    List<ObjectQueryVO> queryPartModelName();

    //查询配件询价（临时查询，正常应该在配件询价接口中）
    @Select(PreInquirySQL.QUERY_SUP_BASE_PART_PRICE)
    @Results(id = "querySupBasePart", value = {
            @Result(column = "part_name", property = "partName"),
            @Result(column = "part_model", property = "partModel"),
            @Result(column = "vice_model", property = "viceModel"),
            @Result(column = "offer_time", property = "offerTime"),
            @Result(column = "offer_price", property = "offerPrice")
    })
    List<ObjectQueryVO> querySupBasePart(String partModel);

    //查询配件报价（临时查询，正常应该在配件报价接口中）
    @Select(PreInquirySQL.QUERY_CRM_BASE_PART_PRICE)
    @Results(id = "queryCrmBasePartPrice", value = {
            @Result(column = "part_name", property = "partName"),
            @Result(column = "part_model", property = "partModel"),
            @Result(column = "vice_model", property = "viceModel"),
            @Result(column = "offer_time", property = "offerTime"),
            @Result(column = "offer_price", property = "offerPrice")
    })
    List<ObjectQueryVO> queryCrmBasePartPrice(String partModel);

    //查询服务报价（临时查询，正常应该在服务报价接口中）
    @Select(PreInquirySQL.QUERY_CRM_BASE_SERVICE_PRICE)
    @Results(id = "queryCrmBaseServicePrice", value = {
            @Result(column = "prod_name", property = "prodName"),
            @Result(column = "offer_time", property = "offerTime"),
            @Result(column = "offer_price", property = "offerPrice")
    })
    List<ObjectQueryVO> queryCrmBaseServicePrice(String prodName);

    //查询询盘记录主键（一次推广可能存在多次询盘）
    @Select(PreInquirySQL.QUERY_PRE_INQUIERY_BY_UID)
    @Results(id = "queryPreInquiryUid", value = {
            @Result(column = "objuid", property = "objuid")
    })
    List<ObjectQueryVO> queryPreInquiryUid(String prePromoteUid);

    //根据主键查询询盘记录，用于询盘回访界面的显示（推广主键查询）
    @Select(PreInquirySQL.QUERY_PRE_INQUIERY_BY_UID2)
    @Results(id = "queryPreInquiryUid2", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PreInquiryQueryVO> queryPreInquiryUid2(String prePromoteUid);

    //根据主键查询询盘记录，用于询盘回访界面的显示（拜访主键查询）
    @Select(PreInquirySQL.QUERY_PRE_INQUIERY_BY_UID3)
    @Results(id = "queryPreInquiryUid3", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PreInquiryQueryVO> queryPreInquiryUid3(String vistUid);

    //根据主键查询询盘记录，用于询盘回访界面的显示（询盘主键查询）
    @Select(PreInquirySQL.QUERY_PRE_INQUIERY_BY_UID4)
    @Results(id = "queryPreInquiryUid4", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PreInquiryQueryVO> queryPreInquiryUid4(String preInquiryUid);

    //新增一条客户信息
    @Insert(PreInquirySQL.SAVE_CRM_BASE)
    int saveCrmBase(CrmBaseSaveDTO crmBaseSaveDTO);

    //修改一条客户信息
    @Update(PreInquirySQL.UPDATE_CRM_BASE)
    int updateCrmBase(CrmBaseUpdateDTO crmBaseUpdateDTO);

    //修改询盘记录表人员主键
    @Update(PreInquirySQL.UPDATE_PRE_INQUIRY_CRM_BASE)
    int updatePreInquiryCrmBase(String prePromoteUid);

}
